package game.mapviewer.popups.losses 
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import game.mapviewer.popups.Popup;
	/**
	 * ...
	 * @author rnk
	 */
	public class LossesPopup extends Popup
	{
		private var bg:MovieClip;
		private var callback:Function;
		private var attackerTileList:UnitsTileList;
		private var defenderTileList:UnitsTileList;
		
		public function LossesPopup() 
		{
			
		}
		
		override public function Init():void 
		{
			super.Init();
			
			bg = new losses_popup();
			addChild(bg);
			
			callback = params.callback;
			
			SetListeners(true);
			
			attackerTileList = new UnitsTileList(bg.attackerTilelist);
			attackerTileList.Init(params.attacker, this);
			
			defenderTileList = new UnitsTileList(bg.defenderTilelist);
			defenderTileList.Init(params.defender, this);
			
			bg.attackerStats.text = "casualties: " + params.attacker.casualties + " units: " + params.attacker.units;
			bg.defenderStats.text = "casualties: " + params.defender.casualties + " units: " + params.defender.units;
		}
		
		private function SetListeners(orly:Boolean):void 
		{
			if (orly)
			{
				bg.okButton.addEventListener(MouseEvent.CLICK, OnButtonClick);
			}
			else
			{
				bg.okButton.removeEventListener(MouseEvent.CLICK, OnButtonClick);
			}
		}
		
		private function OnButtonClick(e:MouseEvent):void 
		{
			switch (e.target) 
			{
				case bg.okButton:
					Close();
					callback();
				break;
				
			}
		}
		
		override public function Die():void 
		{
			attackerTileList.Die();
			defenderTileList.Die();
			SetListeners(false);
			super.Die();
		}
		
	}

}